const express = require('express');
const app = express();
/* 
// 定义中间件
const middleware = (req,res, next) => {
  console.log('中间件执行了');
  // next 放行开关
  req.a = '这是我添加的一个属性';
  next();
}

// 使用中间
// 作为全局中间
// app.use(middleware);
// 作为局部中间件使用 只会拦截 特定 path的路由
app.use('/a', middleware); */


// 题目
const middleware1 = (req, res, next) => {
  console.log('1');
  next();
  console.log('1-1');
}
const middleware2 = (req, res, next) => {
  console.log('2');
  next();
  console.log('2-2');
}
const middleware3 = (req, res, next) => {
  console.log('3');
  next();
  console.log('3-3');
}

app.use(middleware1)
app.use(middleware2)
app.use(middleware3)
app.get('/a', (req, res) => {
  console.log(req.a, 111);
  res.send('a路由')
})
app.get('/b', (req, res) => {
  res.send('b路由')
})
app.listen(9527, () => {
  console.log('start at post 9527');
})